// components/menu/menu.js
var app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    mainmodel: {
      type: Object,
      value: [{
        "url": "/img/top.png",
        }]
    },
    menulist: {
      type: Object,
      value:[
      {
        "id": "1",
        "url": "/img/top.png",
      },
      {
        "id": "2",
        "url": "/img/home_copy.png",
      },
      {
        "id": "3",
        "url": "/img/contact@2x.png",
      },
      {
        "id": "4",
        "url": "/img/phone.png",
      },
    ]},
  },
  
  /**
   * 组件的初始数据
   */
  data: {
   
    scrollTop: 0,
    topNum: 0,
    jieshu:false,
    animationData: {},
    hidden: false,//关注默认显示
  },
  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show: function() {
      this.setData({
        showmenus: app.globalData.showmenus,
        showmenu: app.globalData.showmenu,
      })
      var pages = getCurrentPages();
      let prevPage = pages[pages.length - 1];//上一页面
      prevPage.setData({
        showmenus: this.data.showmenus
      })
      if (prevPage.data.tab != undefined) {
        this.setData({
          tab: prevPage.data.tab,
        })
      } else {
        this.setData({
          tab: false,
        })
      }
    },
    hide: () => {}
  },
  ready:function(){
    this.setData({
      showmenus: app.globalData.showmenus,
      showmenu: app.globalData.showmenu,
    })
    var pages = getCurrentPages();
    let prevPage = pages[pages.length - 1];//上一页面
    prevPage.setData({
      showmenus: this.data.showmenus
    })
    if (prevPage.data.tab != undefined) {
      this.setData({
        tab: prevPage.data.tab,
      })
    } else {
      this.setData({
        tab: false,
      })
    }
    
  },
  /**
   * 组件的方法列表
   */
  methods: {
    showclick:function(){
      console.log("showclick")
      let isshow = !this.data.showmenus;
      this.setData({
        showmenus: isshow,
      })
      app.globalData.showmenus = isshow;
      console.log(app.globalData.showmenus+"menu")
      var pages = getCurrentPages();
      let prevPage = pages[pages.length - 1];//上一页面
      prevPage.setData({
        showmenus: isshow,
      })
      
    },
    itemclick:function(e){
      this.showclick();
      let info = e.currentTarget.dataset.item;
      if (info){
        this.triggerEvent('menuItemClick', {
            "iteminfo":info,
        })
      }
    },
    itemclick0: function (e) {
      var pages = getCurrentPages();
      let prevPage = pages[pages.length - 1];//上一页面
      // 控制滚动
      prevPage.setData({
        topNum: this.data.topNum = 0
      });
    },
    itemclick1: function (e) {
      wx.switchTab({
        url: '/pages/homePage/homePage',
      })
    },
    itemclick2: function (e) {

    },
    itemclick3: function (e) {
      wx.makePhoneCall({
        phoneNumber: '17686605516',
      })
    },
    // 监听滚动条坐标
    scrolltoupper: function (e) {
      if (e.detail.scrollTop > 100) {
        this.setData({
          floorstatus: true
        });
      } else {
        this.setData({
          floorstatus: false
        });
      }
    },
    aaa:function(){
    },
    animationend() {
      if (this.data.jieshu==false) {
        setTimeout(function () {
          this.setData({
            jieshu: true
          })
        }.bind(this), 300)
      } else {
        setTimeout(function () {
          this.setData({
            jieshu: false
          })
        }.bind(this), 300)
      }
    },
  }
})
